<!-- 搜索表单 -->
<template>
  <div class="searchContainer">
    <el-card class="box-card"
             body-style="padding: 22px 22px 0 22px;"
             shadow="never">
      <el-form label-width="77px"
               class="ele-form-search"
               @keyup.enter.native="search"
               @submit.native.prevent
               ref="where"
               :model="where">
        <el-row :gutter="15">
          <el-col v-bind="styleResponsive ? { lg: 8, md: 12 } : { span: 8 }"
                  style="height:  33.2px;">
            <el-form-item label="用户名称:"
                          prop="nickname">
              <el-input clearable
                        v-model="where.nickname"
                        placeholder="请输入用户名称" />
            </el-form-item>
          </el-col>
          <el-col v-bind="styleResponsive ? { lg: 8, md: 12 } : { span: 8 }">
            <el-form-item label="余额类型:"
                          prop="paymentMethod">
              <el-select clearable
                         style="height: 31.2px;"
                         class="ele-block"
                         v-model="where.operateType"
                         @change="(event) => getCategoriesList(event)"
                         placeholder="请选择余额类型">
                <el-option v-for="(item, index) in paymentMethodList"
                           :key="index"
                           :label="item.label"
                           :value="item.value">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col v-bind="styleResponsive ? { lg: 8, md: 12 } : { span: 8 }">
            <el-form-item label="订单编号:"
                          prop="topUpNumber">
              <el-input clearable
                        v-model="where.topUpNumber"
                        placeholder="请输入订单编号" /> </el-form-item>
          </el-col>
          <el-col v-bind="styleResponsive ? { lg: 8, md: 12 } : { span: 8 }">
            <el-form-item label="创建时间:"
                          prop="dateRange">
              <el-date-picker v-model="where.dateRange"
                              type="datetimerange"
                              unlink-panels
                              range-separator="至"
                              start-placeholder="开始时间"
                              end-placeholder="结束时间"
                              :default-time="['00:00:00', '23:59:59']"
                              value-format="yyyy-MM-ddTHH:mm:ss"
                              class="ele-fluid" />
            </el-form-item>
          </el-col>
          <el-col v-bind="styleResponsive ? { lg: 6, md: 12 } : { span: 8 }">
            <div class="ele-form-actions">
              <el-button type="primary"
                         icon="el-icon-search"
                         class="ele-btn-icon"
                         @click="search">
                查询
              </el-button>
              <el-button icon="el-icon-refresh-right"
                         @click="resetForm('where')">重置</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import { reflectState } from '../constant/constant';
export default {
  name: 'SystemUser',
  components: {
    // RegionsSelect
  },
  data () {
    // 默认表单数据
    const defaultWhere = {
      topUpNumber: '',
      dateRange: '',
      nickname: '',
      operateType: ''
    };
    return {
      reflectState,
      // 表单数据
      where: {
        ...defaultWhere
      },
      sumbitForm: {},
      paymentMethodList: [
        {
          value: '1',
          label: '充值'
        },
        {
          value: '2',
          label: '支出'
        },

      ]
    };
  },
  props: {
    typeList: Array,
    oemList: {
      type: Array,
      default: () => []
    },
    secondaryList: {
      type: Array,
      default: () => []
    },
    currentPlatform: {
      type: String,
      default: ''
    }
  },
  computed: {
    // 是否开启响应式布局
    styleResponsive () {
      return this.$store.state.theme.styleResponsive;
    }
  },
  methods: {
    /* 搜索 */
    search () {
      for (const key in this.where) {
        if (key == 'dateRange') {
          let startTime = this.where[key]?.[0];
          let endTime = this.where[key]?.[1];
          this.sumbitForm['createTimeStart'] =
            startTime == undefined ? '' : startTime;
          this.sumbitForm['createTimeEnd'] =
            endTime == undefined ? '' : endTime;
        } else if (key == 'orderAmount') {
          this.sumbitForm['startOrderAmount'] =
            this.where[key].startOrderAmount == undefined
              ? ''
              : this.where[key].startOrderAmount;
          this.sumbitForm['endOrderAmount'] =
            this.where[key].endOrderAmount == undefined
              ? ''
              : this.where[key].endOrderAmount;
        } else {
          this.sumbitForm[key] = this.where[key];
        }
      }
      //   console.log(this.sumbitForm)
      this.$emit('search', this.sumbitForm);
    },
    async getCategoriesList (val) {
      console.log(val)
      this.where.operateType = val

    },
    /*  重置 */
    resetForm (formName) {
      this.$refs[formName].resetFields();

      this.where = {}
      this.sumbitForm = {};
      this.$emit('search', this.sumbitForm);
    }
  }
};
</script>
<style lang="less" scoped>
.searchContainer {
  padding-bottom: 15px;
}
/deep/ .el-form-item__label {
  text-align: inherit;
}
.navList {
  margin-bottom: 25px;
  font-weight: 700;
}
</style>
